export function format(houseId,siteId = 1) {
	let rowNum;
	if (houseId <= 552) {
		siteId = 1
	} else if (houseId <= 1120) {
		siteId = 2
	} else if (houseId <= 1688) {
		siteId = 3
	} else {
		siteId = 4
	}
	switch (siteId) {
		case 1:
			rowNum = 138;
			break;
		case 2:
			rowNum = 142;
			break;
		case 3:
			rowNum = 142;
			break;
		case 4:
			rowNum = 142;
			break;
	}
	if (siteId === 2) {
		houseId -= 138 * 4;
	} else if (siteId === 3) {
		houseId = houseId - 142 * 4 - 138 * 4;
	} else if (siteId === 4) {
		houseId = houseId - 142 * 4 - 142 * 4 - 138 * 4;
	}
	if (houseId > rowNum) {
		const hid_sec =
			houseId % rowNum === 0 ? (houseId % rowNum) + rowNum : houseId % rowNum;
		const hid_fir =
			parseInt(houseId % rowNum) === 0 ?
			parseInt(houseId / rowNum) :
			parseInt(houseId / rowNum) + 1;
		return `${siteId}-${hid_fir}-${hid_sec}`;
	} else {
		return `${siteId}-1-${houseId}`;
	}
}

export function reverseFormat(siteId, hid_fir, hid_sec) {
	let rowNum;
	switch (siteId) {
		case 1:
			rowNum = 138;
			break;
		case 2:
		case 3:
		case 4:
			rowNum = 142;
			break;
		default:
			rowNum = 0;
	}

	let houseId;
	if (hid_fir === 1) {
		if (siteId === 2) {
			houseId = 138 * 4 + hid_sec;
		} else if (siteId === 3) {
			houseId = 138 * 4 + 142 * 4 + hid_sec;
		} else if (siteId === 4) {
			houseId = 138 * 4 + 142 * 4 + 142 * 4 + hid_sec;
		} else {
			houseId = hid_sec;
		}
	} else {
		houseId = (hid_fir - 1) * rowNum + hid_sec;
		if (siteId === 2) {
			houseId += 138 * 4;
		} else if (siteId === 3) {
			houseId += 142 * 4 + 138 * 4;
		} else if (siteId === 4) {
			houseId += 142 * 4 + 142 * 4 + 138 * 4;
		}
	}

	return {
		houseId,
		siteId
	};
}

export function formatSiteId(houseId) {
	let site = 1;
	if (houseId <= 552) {
		site = 1
	} else if (houseId <= 1120) {
		site = 2
	} else if(houseId <= 1688) {
		site = 3
	} else {
		site = 4
	}
	uni.setStorageSync('siteId', site)
	return site
}